﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using University.Workshop.DataAccess;
using University.Workshop.Model;
using System.Threading;
using System.Globalization;
using University.Workshop.DataAccess.LanguagePack.ClientLanguagePack;

namespace University.Workshop.ClientApp
{
    /// <summary>
    /// Interaction logic for UsersOnTable.xaml
    /// </summary>
    public partial class UsersOnTable : Window
    {
        Collection<User> users;
        Collection<UserOnTable> usersOnTableData;
        string language;
        public UsersOnTable(string languageReceived)
        {
            language = languageReceived;
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
            ApplyLanguage();
            InitializeComponent();
            users = null;
            usersOnTableData = null;
        }

        private void ApplyLanguage()
        {
            label1.Content = ClientLanguagePack.UsersOnTableLabel1;
            label2.Content = ClientLanguagePack.UsersOnTableLabel2;
        }
        public UsersOnTable(Collection<User> usersReceived,string languageReceived)
        {
            InitializeComponent();
            language = languageReceived;
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
            ApplyLanguage();
            users = usersReceived;
            usersOnTableData = new Collection<UserOnTable>();
            
            if (users != null)
            {
                labelUser.Content = users[0].Name;
                TranslateDataGrid();
                dataGridUsers.ItemsSource = usersOnTableData;
            }
        }
        public void TranslateDataGrid()
        { 
            for (int i = 0; i < users.Count; i++)
            {
                UserOnTable userReplace = new UserOnTable();
                userReplace.Chips = users[i].Chips;
                userReplace.Name = users[i].Name;
                userReplace.TimeWon = users[i].TimeWon;
                userReplace.UserLevel = users[i].UserLevel;
                usersOnTableData.Add(userReplace);
            }
        }
        public void LoadDataGrid()
        {
            if (users != null)
            {
                labelUser.Content = users[0].Name;
                TranslateDataGrid();
                dataGridUsers.ItemsSource = usersOnTableData;
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        private void dataGridUsers_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

    }
}
